package com.surfilter.modules.module.dao;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.surfilter.modules.module.model.ModuleModel;
import com.surfilter.platform.base.dao.DaoBase;

@Repository
public class ModuleDao extends DaoBase<ModuleModel> {

	@Resource(name = "surfilterSqlMapClient")
	private SqlMapClient sqlMapClient;

	public void initSqlMapClient() {
		this.setSqlMapClient(sqlMapClient);
	}

	public Map<String, String> getAllModulesForCache() {
		Map ret = (Map<String, String>) this.getMapByObject(
				"getAllModulesForCache", null, "moduleName", "serviceName");
		return ret;
	}

	public List<ModuleModel> getAllValidModules() {
		List<ModuleModel> moduleModels = this.getListByObject(
				"getAllValidModules", null);
		return moduleModels;
	}

	public List<ModuleModel> getAllModules() {
		List<ModuleModel> moduleModels = this.getListByObject("getAllModules",
				null);
		return moduleModels;
	}

	public int addModule(ModuleModel moduleModel) {
		Integer key = (Integer) this.addObject("addModule", moduleModel);
		return key;
	}

	public int chgModule(ModuleModel moduleModel) {
		return this.updateObject("chgModule", moduleModel);
	}

	public int delModule(ModuleModel moduleModel) {
		return this.updateObject("delModule", moduleModel);
	}

	public int startModule(List<Integer> moduleIds, int updateUser,
			Date updateTime) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("moduleIds", moduleIds);
		params.put("updateTime", updateTime);
		params.put("updateUser", updateUser);
		return this.updateObject("startModule", params);

	}

	public List<ModuleModel> getAllChildrenByParent(String pname) {
		return this.getListByObject("getAllChildrenByParent", pname);
	}

	public int stopModule(List<Integer> moduleIds, int updateUser,
			Date updateTime) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("moduleIds", moduleIds);
		params.put("updateTime", updateTime);
		params.put("updateUser", updateUser);
		return this.updateObject("stopModule", params);
	}

	public int getChildrenNumber(String name) {
		return (Integer) this.getObjectByObject("getChildrenNumber", name);
	}

	public ModuleModel getModuleById(int moduleId) {
		return (ModuleModel) this.getObjectByObject("getModuleById", moduleId);
	}

	/**
	 * @param pname
	 * @return
	 */
	public ModuleModel getModuleByName(String moduleName) {
		return (ModuleModel) this.getObjectByObject("getModuleByName", moduleName);
	}

	
}
